import plotly.graph_objects as go
import pandas as pd
import plotly.express as px
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib import style
df = pd.read_excel('/Users/anhle/Desktop/Lượng khí thải bình quân đầu người - bản đồ thế giới.xlsx')
fig = go.Figure(data=go.Choropleth(
locations = df['Code'],
z = df['Annual CO2‚ emissions per capita'],
text = df['Entity'],
colorscale = 'portland',
autocolorscale=False,
reversescale=False,
marker_line_color='darkgray',
marker_line_width=0.5,
colorbar_title = 'Annual CO2‚ emissions per capita',
colorbar_ticksuffix ='t',
))
fig.update_layout(
title_text='2021 Annual CO2',
geo=dict(
showframe=False,
showcoastlines=False,
projection_type='equirectangular'
),
annotations = [dict(
x=0.55,
y=0.1,
xref='paper',
yref='paper',
showarrow = False
)]
)
fig.show()
print(px.colors.qualitative.Plotly)
['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']
df= pd.read_excel('/Users/anhle/Desktop/Data qq/phát thải co2 theo ngành trên toàn thế giới 2020.xlsx')
fig= px.sunburst(df, path= ['Sector','Sub-sector','Sub-sector further breakdown'], values = 'Emissions share %',
width= 650, height= 650, color='Sector',
color_discrete_map = {'Energy': '#FF6692',
'Industrial processes': '#6E899C',
'Agriculture, Forestry & Land Use ': '#00CC96',
'Waste': '#17BECF'})
fig.update_layout(title_text='Sunburst',
margin={"r":0,"t":100,"l":3,"b":3},paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',font_color='#333333')
fig.update_layout(margin=dict(t=20, b=20, r=20, l=20))
fig.show()
C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py:1637: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df_all_trees = df_all_trees.append(df_tree, ignore_index=True) C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py:1637: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df_all_trees = df_all_trees.append(df_tree, ignore_index=True) C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py:1637: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df_all_trees = df_all_trees.append(df_tree, ignore_index=True)
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='World')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="World", xaxis_title="Year", yaxis_title="CO2")
fig.show()
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='Africa')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="Africa", xaxis_title="Year", yaxis_title="CO2", hovermode="closest", dragmode="zoom")
fig.show()
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='Asia')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="Asia", xaxis_title="Year", yaxis_title="CO2")
fig.show()
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='Europe')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="Europe", xaxis_title="Year", yaxis_title="CO2")
fig.show()
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='Oceania')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="Oceania", xaxis_title="Year", yaxis_title="CO2")
fig.show()
df = pd.read_excel("/Users/anhle/Downloads/C02 theo lĩnh vực qua các năm.xlsx", sheet_name='America')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["Buildings"], name="Buildings", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Industry"], name="Industry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Electricity and heat"], name="Electricity and heat", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Other fuel combustion"], name="Other fuel combustion", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Transport"], name="Transport", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Land-use change and forestry"], name="Land-use change and forestry", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["Manufacturing and construction"], name="Manufacturing and construction", mode="lines + markers"))
fig.update_layout(
title="America", xaxis_title="Year", yaxis_title="CO2")
fig.show()
df = pd.read_csv('/Users/anhle/Desktop/Data qq/Nhiệt độ TB toàn cầu.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Year"], y=df["GAT1"], name="Global", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["GAT2"], name="Northern Hemisphere", mode="lines + markers"))
fig.add_trace(go.Scatter(x=df["Year"], y=df["GAT3"], name="Southern Hemisphere", mode="lines + markers"))
fig.update_layout(
title="Global average temperature anomaly relative to 1961-1990", xaxis_title="Year", yaxis_title="temperature anomaly")
fig.show()
fuel_df = pd.read_csv('/Users/anhle/Downloads/per-capita-co2-by-fuel.csv')
ennity_df = fuel_df['Entity']
coal_df = fuel_df['Coal']
oil_df = fuel_df['Oil']
gas_df = fuel_df['Gas']
flaring_df = fuel_df['Flaring']
cement_df = fuel_df['Cement']
industry_df = fuel_df['Industry']
xpos = np.arange(len(ennity_df))
barWidth = 0.4
plt.figure(figsize=(10,7))
plt.bar(xpos, coal_df, color='gray', width= barWidth, label='Coal')
plt.bar(xpos, oil_df, bottom=coal_df, color='royalblue', width= barWidth, label='Oil')
plt.bar(xpos, gas_df, bottom=coal_df, color='red', width= barWidth, label='Gas')
plt.bar(xpos, flaring_df, bottom=coal_df, color='purple', width= barWidth, label='Flaring')
plt.bar(xpos, cement_df, bottom=coal_df, color='green', width= barWidth, label='Cement')
plt.bar(xpos, industry_df, bottom=coal_df, color='yellow', width= barWidth, label='Industry')
plt.xlabel('Continent')
plt.ylabel('Annual CO2 emissions per capita')
plt.title('Per capital CO2 by fuel')
plt.xticks(xpos, ennity_df)
plt.legend()
<matplotlib.legend.Legend at 0x239bc105220>
fuel_df.head(6)
| Entity | Coal | Oil | Gas | Flaring | Cement | Industry | |
|---|---|---|---|---|---|---|---|
| 0 | Africa | 0.311429 | 0.399546 | 0.234221 | 0.040412 | 0.055799 | NaN |
| 1 | Asia | 2.548085 | 1.024128 | 0.690949 | 0.025913 | 0.289461 | 0.042698 |
| 2 | Europe | 1.653074 | 2.526259 | 2.595303 | 0.114441 | 0.145982 | 0.077297 |
| 3 | Oceania | 3.624329 | 3.897421 | 1.914228 | 0.410848 | 0.072976 | 0.097380 |
| 4 | America | 2.070175 | 6.068896 | 4.071080 | 0.250474 | 0.237061 | 0.060591 |
| 5 | World | 1.893923 | 1.496614 | 1.001585 | 0.052663 | 0.211472 | 0.037443 |
worldMap = pd.read_csv('/Users/anhle/Downloads/Mục-tiêu-thải-ròng-bằng-không-1.csv')
px.choropleth(worldMap,
locations="Code",
color="Status of net-zero target",
hover_name="Entity",
color_continuous_scale='Cividis',
height=700,width = 1000
)